package org.CurrencyService;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

public class DownloaderFile {

	public void copyFileFromNBP(String fileName, String copyFileName, String NBPUrl) {
		InputStream inStream = null;
		OutputStream outStream = null;
		try {
			URL url = new URL(NBPUrl + fileName);

			inStream = url.openStream();
			outStream = new FileOutputStream(copyFileName);

			byte[] buffer = new byte[1024];
			int length;
			while ((length = inStream.read(buffer)) > 0) {
				outStream.write(buffer, 0, length);
			}

			inStream.close();
			outStream.flush();
			outStream.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
